package com.heima.tess4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class Application {

    // 识别图片中的文字
    public static void main(String[] args) throws TesseractException {

        // 1.创建实例
        ITesseract tesseract = new Tesseract();

        // 2.设置字体库路径
        tesseract.setDatapath("D:\\Tools\\Develop\\JavaCode\\heima-leadnews\\heima-leadnews-test\\tess4j-demo\\src\\main\\resources");

        // 3.设置语言-->简体中文
        tesseract.setLanguage("chi_sim");

        // 4.识别图片
        File file = new File("D:\\Tools\\Develop\\JavaCode\\heima-leadnews\\heima-leadnews-test\\tess4j-demo\\src\\main\\resources\\test.png");
        String result = tesseract.doOCR(file);

        System.out.println("识别结果为：" + result.replaceAll("\\r|\\n", "-"));
    }
}
